<template>
  <div class="video-container" :style="defaultStyle" :class="isActiveClass">
    <div class="video-content" :style="contentStyle">
      <div class="video-header" v-if="contentData.show_title">
        <div class="video-title" :style="itemStyle">
          {{ contentData.title }}
        </div>
        <div v-if="contentData.show_more" class="video-more">{{ contentData.show_more_text }}</div>
      </div>

      <div class="carousel" v-if="contentData.layout === 'single'">
        <div
          class="video-wrapper"
          v-for="(item, index) in contentData.default_sub_list"
          :key="index"
        >
          <img class="img-style" :src="item.poster" />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
  const props = defineProps({
    contentData: {
      type: Object,
      default: () => ({})
    },
    isActiveClass: {
      type: String
    }
  })

  const defaultStyle = computed(() => {
    const s = props.contentData.style
    return {
      paddingTop: s.paddingTop,
      paddingLeft: s.paddingLeft,
      paddingRight: s.paddingRight,
      paddingBottom: s.paddingBottom
    }
  })

  const contentStyle = computed(() => {
    const s = props.contentData.style
    return {
      borderRadius: s.borderRadius,
      backgroundColor: s.backgroundColor,
      overflow: 'hidden'
    }
  })

  const itemStyle = computed(() => {
    const s = props.contentData.itemStyle || {}
    return {
      fontSize: s.fontSize ? s.fontSize + 'px' : '15px',
      color: s.color,
      fontWeight: s.fontWeight
    }
  })
</script>

<style scoped lang="scss">
  .video-container {
    width: 100%;
    box-sizing: border-box;

    .video-content {
      padding: 12px;
    }

    .video-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 12px;

      .video-title {
        font-weight: bold;
      }

      .video-more {
        font-size: 14px;
        color: #999;
      }
    }

    .video-wrapper {
      width: 100%;
      overflow: hidden;
    }

    .img-style {
      width: 100%;
      height: 100%;
      object-fit: cover;
      border-radius: 12px;
    }
  }

  .active-component {
    border: 1px solid var(--el-color-primary);
  }
</style>
